package com.zuoqi.easywork.system.controller;

import com.zuoqi.common.utils.IMap;
import com.zuoqi.common.utils.SessionUtil;
import com.zuoqi.common.utils.TreeHelper;
import com.zuoqi.common.utils.TreeNode;
import com.zuoqi.easywork.system.service.MenuService;
import com.zuoqi.easywork.userManage.model.TcResc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class menuController {
    @Autowired
    private MenuService menuService;
    @RequestMapping("/menuController/getUserMenuTree")
    @ResponseBody
    public List<TreeNode> selectUserMenuTree(HttpServletRequest request) {
        IMap params = new IMap(request);
        HttpSession session = request.getSession();
        String userId = SessionUtil.getLoginUserId(session);
        params.put("userId",userId);
        List<TcResc> list = menuService.selectUserMenuTree(params);
        //转成标准的树结构
        return TreeHelper.convertMenuTree(list, null);

    }
}
